<template>
    <div class="app-container">
        <div class="filter-container">
            <el-input v-model="listQuery.title" size="small" placeholder="请输入标题" clearable class="filter-item" />

            <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            <el-button size="small" icon="el-icon-refresh" @click="refresh">重置</el-button>
            <el-button size="small" type="primary" icon="el-icon-plus" @click="add">新增</el-button>
        </div>
        <el-table v-loading="listLoading" :data="tableData" element-loading-text="Loading" border fit height="580px"
            class="table-container" highlight-current-row>
            <el-table-column type="index" label="序号" prop width="50"></el-table-column>
            <el-table-column label="专题名称" align="center" prop="title"> </el-table-column>
            <el-table-column label="操作" align="center" prop="rowTotal" width="200">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination style="margin-top: 20px" v-show="total > 0" :total="total" :page.sync="listQuery.pageNo"
            :limit.sync="listQuery.pageSize" @pagination="fetchData" />
    </div>
</template>

<script>
import { BigSreenList, deleteBigScreenById } from '@/http/api/myHttp.js'
import { formatX } from "@/utils/fontSize"
export default {
    components: {},
    data() {
        return {
            total: 0,
            tableData: [],
            listLoading: false,
            listQuery: {
                pageNo: 1,
                pageSize: 10,
                title: ""
            },
            currentRow: {},
        }
    },
    created() {
        this.fetchData()
        // this.getCronList()
    },
    methods: {
        add() {
            this.$router.push({
                path: '/themeTable/ztgl-add',
                query:{
                    type:'add'
                }
            })
        },
        handleEdit(row) {
            this.$router.push({
                path: '/themeTable/ztgl-add',
                query: {
                    rowData: JSON.stringify(row),
                    type: 'edit'
                }
            })
        },
        handleClose() {
            this.taskDisabled = true
            this.updateShow = false
        },
        formatX,
        search() {
            this.fetchData()
        },
        refresh() {
            this.listQuery = {
                pageNo: 1,
                pageSize: 10
            }
            this.fetchData()
        },
        fetchData() {
            let params = { ...this.listQuery }
            for (let key in params) {
                if (!params[key]) {
                    delete params[key]
                }
            }
            this.listLoading = true
            BigSreenList(params).then((res) => {
                this.listLoading = false
                if (res.code == 0) {
                    this.tableData = res.data.records

                    this.total = res.data.total
                }
            })
        },
        handleDelete(row) {
            this.$confirm('是否确认删除名称为"' + row.title + '"的数据项?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    const loading = this.$loading({
                        lock: true,
                        text: '正在删除...',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.5)'
                    })
                    deleteBigScreenById({ objectId: row.objectId }).then((res) => {
                        loading.close()
                        if (res.code == 0) {
                            this.$message({
                                type: 'success',
                                message: '删除成功！'
                            })
                            this.fetchData()
                        }
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        }
    }
}
</script>
<style lang="scss" scoped>
.app-container {
    // box-sizing: border-box;
    width: 100%;
    height: 100%;
    // padding: 18px 24px;
}

.taskInfo {
    .info-item {
        margin: 10px 0;
        display: flex;
        align-items: center;
        justify-content: flex-start;
    }
}

.filter-container {
    display: flex;
    justify-content: flex-start;
}

.filter-item {
    width: 300px;
    margin-right: 10px;
}

.el-table {
    ::v-deep {
        margin-top: 20px;

        .el-table__header {
            border-radius: 6px;
            overflow: hidden;
        }

        .el-table__cell {
            height: 50px;
            padding: 0;
        }

        .is-leaf {
            background-image: linear-gradient(to top, rgba(128, 191, 255, 1), rgba(51, 153, 255, 1));
            font-size: 14px;
            font-weight: 700;
            letter-spacing: 0px;
            line-height: 24px;
            color: rgba(255, 255, 255, 1);
            border-right: 1px solid white;
        }
    }
}

.operate_area {
    width: 80px;
    display: flex;
    justify-content: space-between;
    margin: 0 auto;

    img {
        cursor: pointer;
    }
}

.captcha-img.el-switch.is-disabled {
    opacity: 1;

}

.update-wrap {}
</style>
<style>
.el-switch__core {
    cursor: pointer;
}
</style>
